<template>
  <!-- 表单管理 -->
  <div class="centent">
    <div style="background-color: #FFFFFF;padding: 15px;">
      <div class="ipt_box">
        <span>名称：</span> <el-input v-model="input" placeholder="请输入名称" clearable style="width: 20%;" />
        <el-button style="margin-left: 2%;" type="primary" icon="el-icon-search" @click="fromsearch">搜索</el-button>
      </div>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="formName" label="名称" />
        <el-table-column prop="createBy" label="发起人" />
        <el-table-column prop="createTime" label="发起时间" />
        <el-table-column prop="type" label="操作">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" round @click="changefrom(scope.row, scope.$index)">修改</el-button>
            <el-button size="mini" type="danger" round @click="removefrom(scope.row, scope.$index)">删除</el-button>
          </template>
        </el-table-column>

      </el-table>
      <div style="margin-left: 50%;margin-top: 10px;">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[ 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalcount"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>

    </div>
    <el-dialog
      title="提示"
      :visible.sync="centerDialogVisible"
      width="30%"
      center
    >
      <span>确定要删除此项吗?</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="isok()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      centerDialogVisible: false,
      //  列表数据源
      tableData: [],
      currentPage: 1,

      pageSize: 10,
      totalcount: 0,
      // 搜索框
      input: '',
      addvalue: true,
      jianvalue: true,
      removeid: null,
      removeindex: null
    }
  },
  created() {
    this.getlist()
  },
  methods: {

    // 编辑表单
    changefrom(row, index) {
      console.log('row', row)
      this.$router.push({
        path: '/changeform',
        query: {
          fromid: row.id,
          fromname: row.formName
        }
      })
    },
    // 搜索
    fromsearch() {
      this.$Http.fromsearch({ pageNumber: this.currentPage, pageSize: this.pageSize, formName: this.input }).then(res => {
        if (res.code === 200) {
          this.tableData = res.result.totalElements
          this.tableData = res.result.content
        } else {
          this.$message({
            type: 'error',
            message: res.message
          })
        }
      }).catch(err => {
        console.log('err', err)
      })
    },
    // 删除
    removefrom(row, index) {
      this.centerDialogVisible = true
      this.removeid = row.id
      this.removeindex = index
    },
    isok() {
      this.centerDialogVisible = false
      this.$Http.removefrom(this.removeid).then(res => {
        if (res.code === 200) {
          this.tableData.splice(this.removeindex, 1)
          this.getlist()
          this.$message({
            message: '删除成功!',
            type: 'success'
          })
        }
      }).catch(err => {
        console.log('err', err)
      })
    },
    // 获取列表
    getlist() {
      this.$Http.biaodanlist({
        pageNumber: this.currentPage,
        pageSize: this.pageSize,
        formName: this.input }).then(res => {
        if (res.code === 200) {
          this.totalcount = res.result.totalElements
          this.tableData = res.result.content
        }
      }).catch(err => {
        console.log('err', err)
      })
    },

    // 分页
    handleSizeChange(val) {
      this.pageSize = val
      this.getlist()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getlist()
    }

  }
}
</script>
<style lang="scss" scoped>
  .centent {
    padding: 25px;

    .ipt_box {
      width: 100%;
      padding: 15px;
      display: flex;
      span{
        text-align: center;
        padding-top: 0.6%;
        margin-left: 2%;
      }
    }
  }
</style>
